/*
CheckoutCheck is Copyright 2010 Polyclef Software LLC.

This file is part of CheckoutCheck.

    CheckoutCheck is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    CheckoutCheck is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with CheckoutCheck.  If not, see <http://www.gnu.org/licenses/>.
*/

package com.checkoutcheck;

import java.math.BigDecimal;
import java.math.MathContext;

public class ItemSummary implements Comparable<Object> {

	private String itemName = "";
	private BigDecimal itemPrice;
	private int itemCount = 0;
	private BigDecimal totalGross = new BigDecimal("0.00");
	private BigDecimal totalNet = new BigDecimal("0.00");
	private boolean androidTransactions = true;
	
	
	public ItemSummary(String newItemName) {
		itemName = newItemName;
	}
	
	public void setItemName(String newItemName) {
		itemName = newItemName;
	}
	
	public String getItemName() {
		return itemName;
	}
	
	public void incrementItemCount() {
		itemCount++;
	}
	
	public int getItemCount() {
		return itemCount;
	}
	
	public void setItemPrice(BigDecimal newItemPrice) {
		itemPrice = newItemPrice;
	}
	
	public BigDecimal getItemPrice() {
		return itemPrice;
	}
	
	public void setAndroidTransactions(boolean newAndroidTransactions) {
		androidTransactions = newAndroidTransactions;
	}
	
	public boolean getAndroidTransactions() {
		return androidTransactions;
	}
	
	public void calcTotalGross() {
		MathContext mc = new MathContext(BigDecimal.ROUND_HALF_UP);
		totalGross.setScale(2, BigDecimal.ROUND_HALF_UP);
		BigDecimal itemNum = new BigDecimal(Integer.toString(itemCount));
		totalGross = itemNum.multiply(itemPrice,mc);
	}
	
	public void calcTotalNet() {
		MathContext mc = new MathContext(BigDecimal.ROUND_HALF_UP);
		totalNet.setScale(2, BigDecimal.ROUND_HALF_UP);
		itemPrice.setScale(2, BigDecimal.ROUND_HALF_UP);
		for (int i = 0; i < itemCount; i++) {
	    	BigDecimal percentage = new BigDecimal("0.70");
	    	BigDecimal tempNetItemPrice = itemPrice.multiply(percentage,mc);
	    	tempNetItemPrice = tempNetItemPrice.setScale(2, BigDecimal.ROUND_HALF_UP);
	    	totalNet = totalNet.add(tempNetItemPrice);	
	    	//System.out.println(tempNetItemPrice);
		}
		//System.out.println(totalNet);
	}
	
	public BigDecimal getTotalGross() {
		return totalGross;
	}
	
	public BigDecimal getTotalNet() {
		return totalNet;
	}

	@Override
	public int compareTo(Object arg0) {
		String s1 = itemName;
		ItemSummary tempItemSummary = (ItemSummary) arg0;
		String s2 = tempItemSummary.getItemName();		 
		return s1.compareTo(s2);
	}
	
	
}
